let v = new Vue({
    el:'#app',
    data:{
        id:'',
        pageInfo:{},
        keywords:''
    },
    methods:{
        findUserPage:function (pageNum,pageSize){
            axios({
                url:`user/findUserPage/${pageNum}/${pageSize}`,
                method:"POST",
                data: {"keywords":this.keywords}
            }).then(response=>{
                this.pageInfo = response.data.data;
            }).catch(error=>{
                layer.msg(error.message);
            })
        },
        changeFocused:function (userId,focused){
            let focus = !focused;
            axios({
                url:`user/changeFocused`,
                method: "PUT",
                data:{
                    "focus":focus,
                    "userId":userId
                }
            }).then(response=>{
                if (response.data.flag){
                    if (focus){
                        layer.msg("关注成功")
                    }else {
                        layer.msg("取关成功")
                    }
                    //刷新页面
                    this.findUserPage(1,5);
                }
            }).catch(error=>{
                layer.msg(error.message);
            })
        },
        toUserDetail:function (id){
            sessionStorage.setItem("userId", id);
            location.href=`user/toUserDetail`
        }
    },
    created:function (){
        this.findUserPage(1,5);
        this.id = sessionStorage.getItem("myId");
    }
})